import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

showDropDown({
  required GlobalKey key,
  required List<UsuallyModel> list,
  required Function(int)? onTap,
}) {
  var robj = key.currentContext?.findRenderObject() as RenderBox?;
  if (robj == null) {
    return;
  }
  Get.log(robj.size.height.toString());
  var offset = robj.localToGlobal(Offset(robj.size.width, robj.size.height));
  showCupertinoDialog(
      context: Get.context!,
      barrierDismissible: true,
      builder: (context) {
        return Column(
          crossAxisAlignment: CrossAxisAlignment.end,
          children: [
            Container(
              margin: EdgeInsets.only(top: offset.dy, right: 12.r),
              width: 160.w,
              decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(4.r)),
              child: Column(
                children: list
                    .map(
                      (e) => Container(
                        padding: EdgeInsets.symmetric(horizontal: 12.r),
                        height: 50.r,
                        decoration: UnderlineTabIndicator(
                            insets: EdgeInsets.symmetric(horizontal: 12.r),
                            borderSide: const BorderSide(
                                width: 1, color: Color(0xffeeeeee))),
                        child: Row(
                          children: [
                            Visibility(
                              child: e.iconData != null
                                  ? Icon(
                                      e.iconData,
                                      size: 24.r,
                                    )
                                  : e.url != null
                                      ? Image.asset(e.url!,
                                          width: 24.r,
                                          height: 24.r,
                                          fit: BoxFit.contain)
                                      : const SizedBox(),
                            ),
                            Text(
                              e.name,
                              style: TextStyle(
                                  color: const Color(0xff333333),
                                  fontSize: 15.sp),
                            )
                          ],
                        ),
                      ),
                    )
                    .toList(),
              ),
            ),
          ],
        );
      });
}

class UsuallyModel {
  String? url;
  IconData? iconData;
  String name;
  int? unReadCount;
  VoidCallback? onTap;
  UsuallyModel(
      {this.url,
      this.iconData,
      required this.name,
      this.unReadCount,
      this.onTap});
}
